/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * @fileOverview 支付平台1.0
 * 兴趣点轨迹下载业务逻辑
 * @author fengbj
 * @ date 2010-3-11 14:09:52
 */
if (!window.mapbar) {
    window.mapbar = {};
}
if (!window.mapbar.pay) {
    window.mapbar.pay = {};
}
if (!window.mapbar.pay.device) {
    window.mapbar.pay.device = {};
}

(function(_this){
    $.extend(_this , {
        getBrands : function(src , target){
            $("#"+target +">option").remove();
            var id = $("#"+src+" >option:selected").attr("id");
            if(typeof id == "undefined"){
                _this.getDeviceModel(target,"deviceModel");
                $("#" + target).change(function(){
                    mapbar.pay.device.getDeviceModel("brand","deviceModel");
                });
                return;
            }
            //alert(id)
            $.ajax({
                url : "/ajax/getBrandsByCorpId.action",
                data : {
                    corpId : id
                },
                type : "post",
                dataType : "json",
                success : function(msg){
                    if(typeof msg != "undefined" && msg != null && typeof msg.list != "undefined"){
                       
                        $.each(msg.list , function(i , n){
                            var option = document.createElement("option");
                            option.id = n.id;
                            option.value = n.brand;
                            option.innerHTML = n.brand;
                            $("#" + target).append(option);
                        });

                         

                    }
                    _this.getDeviceModel(target,"deviceModel");
                    $("#" + target).change(function(){
                        mapbar.pay.device.getDeviceModel("brand","deviceModel");
                    });
                }

            });

        },
        getCorp : function(target){
            $("#"+target +">option").remove();
            $.ajax({
                url : "/ajax/getCorp.action",
                data : {},
                type : "post",
                dataType : "json",
                success : function(msg){
                    if(typeof msg != "undefined" && msg != null && typeof msg.list != "undefined"){
                       
                        $.each(msg.list , function(i , n){
                            var option = document.createElement("option");
                            option.id = n.id;
                            option.value = n.corp;
                            option.innerHTML = n.corp;
                            $("#" + target).append(option);
                        });
                        
                    }
                    _this.getBrands(target,"brand");
                    $("#" + target).change(function(){
                        mapbar.pay.device.getBrands("corp","brand");
                    });
                }

            });
        },
        getDeviceModel : function(src , target){
            $("#"+target +">option").remove();
            var id = $("#"+src+" >option:selected").attr("id");
            if(typeof id == "undefined"){
                return;
            }
            $.ajax({
                url : "/ajax/getDeviceModel.action",
                data : {
                    brandId : id
                },
                type : "post",
                dataType : "json",
                success : function(msg){
                    if(typeof msg != "undefined" && msg != null && typeof msg.list != "undefined"){
                       
                        $.each(msg.list , function(i , n){
                            var option = document.createElement("option");
                            option.id = n.id;
                            option.value = n.name;
                            option.innerHTML = n.name;
                            $("#" + target).append(option);
                        });
                    }
                }

            });

        }

        

    })
})(mapbar.pay.device)